package sms

import "net/url"

type SmsVendor interface {
	Send()
}

var env = "dev"
var smsChn = make(chan SmsVendor)

var CloseSMS bool

func Init(runmode string) {
	env = runmode
	go func() {
		for {
			doSend()
		}
	}()
}

func SendTo(vendor SmsVendor) {
	if !CloseSMS {
		if env != "dev" {
			smsChn <- vendor
		}
	}
}

func doSend() {
	vendor := <-smsChn
	vendor.Send()
}

func NewMongateApi(phone, text string) *MongateApi {
	return &MongateApi{phone: phone, text: text}
}

func NewYunpianApi(phone string, tplId int) *YunpianApi {
	api := &YunpianApi{phone: phone, tplId: tplId}
	api.tplParams = make(url.Values)
	return api
}
